package com.study.jyg.rxjava2study.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.widget.SeekBar;

import com.study.jyg.rxjava2study.R;
import com.study.jyg.rxjava2study.widget.CircleScaleView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 圆形比例图
 */
public class CircleScaleViewActivity extends AppCompatActivity implements SeekBar.OnSeekBarChangeListener {

    @BindView(R.id.toolBar)
    Toolbar toolBar;
    @BindView(R.id.cs_my_scale)
    CircleScaleView mScaleView;
    @BindView(R.id.sb_one)
    SeekBar sbOne;
    @BindView(R.id.sb_two)
    SeekBar sbTwo;
    @BindView(R.id.sb_three)
    SeekBar sbThree;
    @BindView(R.id.sb_four)
    SeekBar sbFour;
    private float lifeCost;
    private float trafficCost;
    private float communicateCost;
    private float entertainmentCost;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_circle_scale_view);
        ButterKnife.bind(this);
        setSupportActionBar(toolBar);
        toolBar.setNavigationOnClickListener(v -> finish());

        initData();
    }

    private void initData() {
        sbOne.setOnSeekBarChangeListener(this);
        sbTwo.setOnSeekBarChangeListener(this);
        sbThree.setOnSeekBarChangeListener(this);
        sbFour.setOnSeekBarChangeListener(this);
        lifeCost = sbOne.getProgress();
        trafficCost = sbTwo.getProgress();
        communicateCost = sbThree.getProgress();
        entertainmentCost = sbFour.getProgress();
        mScaleView.setCostPercent(lifeCost, trafficCost, communicateCost, entertainmentCost);
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        float values = (float) (seekBar.getProgress());
        switch (seekBar.getId()) {
            case R.id.sb_one:
                lifeCost = values;
                break;
            case R.id.sb_two:
                trafficCost = values;
                break;
            case R.id.sb_three:
                communicateCost = values;
                break;
            case R.id.sb_four:
                entertainmentCost = values;
                break;
        }
        mScaleView.setCostPercent(lifeCost, trafficCost, communicateCost, entertainmentCost);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }
}
